package org.liuyunfeng.filter;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author: TanJingyu
 * @create: 2022-03-11 13:49
 **/
@WebFilter(urlPatterns = {"/**", "/*"})
@Configuration
@Profile("dev")
public class RootFilter implements Filter, ApplicationContextAware {
    private ApplicationContext context;

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("来了啊......" + Thread.currentThread().getName());
        chain.doFilter(request, response);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    @Bean
    public String testString() {
        return ";;";
    }
}

    